function editFixedPackegeArchived(id){
	$("#addtableFixedArchived").attr("style","display:;");
	$("#addtableFixedArchived").load("/adminconsole/PriceManager/Fixed/addfixedpackage.jsp",function(responseText, textStatus, XMLHttpRequest) {
		$("#tableFixedArchived").attr("style","display:none");
		$("#suggest").html(editpackage);
		$("[name=save]").attr("onclick","addfixedpackage('archived')");
		$("[name=cancel]").attr("onclick","cancelFixedPackege('archived')");
		loadAddFixpackageData(id);
		callDatePicker();
	});
}

function showArchivedFixedPackage(id,type){
	if(id == null||type=="archived"||type=="edittime"||type=="edit"){
		if(type=="edit"){
			if(successEditTask!=null)
				clearTimeout(successEditTask);
			$("#edited").hide();
			$("#edited").show();
			$("#editsuccess").html($("#packagename").val());
			successEditTask = setTimeout(function(){$("#edited").hide(1000);}, 5000);
			$("#addtableFixedArchived").attr("style","display:none;");
			$("#tableFixedArchived").attr("style","display:;");
		}
		if($("[name=maxEntriesarchived]").val() == null){
			var line = 10;
		}else{
			var line = $("[name=maxEntriesarchived]").val();
		}
		if($("[name=selectpagearchived]").val() == null){
			var pagePointer = 1; 
		}else{
			var pagePointer = $("[name=selectpagearchived]").val(); 
		}
	}else if(id == "nextarchived"){
		var line = $("[name=maxEntriesarchived]").val();
		var pagePointer = parseInt($("[name=selectpagearchived]").val())+1;
	}else if(id == "previousarchived"){
		var line = $("[name=maxEntriesarchived]").val();
		var pagePointer = parseInt($("[name=selectpagearchived]").val())-1;		
	}
	var link = "/fixedpackageservice";
	var data = { func: "getallarchivedfixedpackage",
				offset: (line*pagePointer)-line,
				line: line,
				pagePointer: pagePointer
					}
	simpleservice(link,data,showArchivedFixedPackageList);
}

function showArchivedFixedPackageList(data,type){
	if(type=="add"){
		if(successAddTask!=null)
			clearTimeout(successAddTask);
		$("#added").hide();
		$("#added").show();
		$("#addsuccess").html($("#packagename").val());
		successAddTask = setTimeout(function(){$("#added").hide(1000);}, 5000);
		$("[id=addtableFixedArchived]").attr("style","display:none;");
		$("[id=tableFixedArchived]").attr("style","display:;");
	}else if(type=="edit"){
		if(successEditTask!=null)
			clearTimeout(successEditTask);
		$("#edited").hide();
		$("#edited").show();
		$("#editsuccess").html($("#packagename").val());
		successEditTask = setTimeout(function(){$("#edited").hide(1000);}, 5000);
		$("[id=addtableFixedArchived]").attr("style","display:none;");
		$("[id=tableFixedArchived]").attr("style","display:;");
	}
	cleartoggleSelectArchived();
	var objArray2 = new Array();
	objArray2 = JSON.parse(data);
	$("#counterFixed").html(objArray2[5]);
	$("#counterArchivedFixed").html(objArray2[0]);
	var checkLogOut = checkSessionAdmin(objArray2);
	if(checkLogOut)
		return;
	var sumtext = "";
	var pageAmount = Math.ceil(objArray2[0]/objArray2[2]);
	var line = objArray2[2];
	var pagePointer = objArray2[1];
	var objArray = objArray2[3];
	dateFormatString =  objArray2[4];
	/*if(objArray.length==0){
		$("#showList").append("<tr><td colspan='8' style='text-align:center;'>Data Empty</td></tr>");
		return;
	}*/
	for(var i = 0;i< objArray.length+1;i++){
			if(i != objArray.length ){
				for(var x =0;x<objArray[i]["packagepriceList"].length ;x++){
					var text = "";
					if(objArray[i]["isForever"]){
						var packaetime = "Forever";
						var tdpackage = "<td  align=\"center\" rowspan=\""+objArray[i]["packagepriceList"].length+"\">"+packaetime+"</td>";
					}else{
						var packagetime = new Date(objArray[i]["from"]).getFormatedString()+
						" - "+new Date(objArray[i]["to"]).getFormatedString();
						if(new Date(objArray[i]["to"]).getTime()<=getServerDateTime().getTime()){
							var tdpackage = "<td  align=\"center\" rowspan=\""+objArray[i]["packagepriceList"].length+"\"><span class='expired-text'>"+ExpiredPackage+"</span><br><span class='hide-text'>"+packagetime+"</span></td>";
						}else{
							var tdpackage = "<td  align=\"center\" rowspan=\""+objArray[i]["packagepriceList"].length+"\"><span class='hide-text'>"+packagetime+"</span></td>";
						}
					}
					
					if(x == 0){
						var sendData ="";
						for(var pk =0;pk<objArray[i]["packagepriceList"].length ;pk++){
							var  checksub = 0;
							var obj = objArray[i]["packagepriceList"][pk];
							for (var k in obj)
							{
							    if(obj.roomtype!=undefined && checksub == 0){
							    	checksub = 1;
							    	var newsubListObjString = new Array();
						    		var objsub = obj.roomtype;
						    		for (var j in objsub)
									{
						    			if (objsub.hasOwnProperty(j))
									    {
											objsub[j] = String(objsub[j]);
									    }
									}
						    		newsubListObjString.push(objsub);
						    		obj.roomtype = newsubListObjString;
							    }
								if (obj.hasOwnProperty(k))
							    {
							        if(k=="roomtype")
							        	continue;
									obj[k] = String(obj[k]);
							    }
							}
							var re2 = /"/gi;
							sendData += JSON.stringify(obj).replace(re2, "'")+",";//set format for data in javascript
						}
						var sendDataSet = sendData.substring(0,sendData.length - 1);
						var sendDataArray = "["+sendDataSet+"]";
						if(objArray[i]['status']=="true"||objArray[i]['status']==true){
							check = "checked";
						}else{
							check = "";
						}
						text = "<tr id=\"row_"+objArray[i]['id']+"\" style=\"border: 0px;\"> " +
						"<td align=\"center\" rowspan=\""+objArray[i]["packagepriceList"].length+"\"> "+(i+1)+" </td>"+
						"<td rowspan=\""+objArray[i]["packagepriceList"].length+"\"><input type=\"checkbox\" id=\"id_"+i+"\" name=\"idarchived[]\" value=\""+objArray[i]['id']+"\"> </td>"+
						"<td align=\"left\" rowspan=\""+objArray[i]["packagepriceList"].length+"\">"+objArray[i]['packageName']+" </td>"+
						"<td align=\"left\" rowspan=\""+objArray[i]["packagepriceList"].length+"\">" +
							'<span class="link" onclick="showdetailRoomType($(this),'+sendDataArray+');">'+viewDetail+'</span>' +
						"</td>"+
			            "<td align=\"left\">"+
			            	'<span class="link" onclick="showdetailPrice($(this),'+sendDataArray+');">'+viewDetail+'</span>'+
						"</td> "+
							tdpackage+
						"<td align=\"center\" rowspan=\""+objArray[i]["packagepriceList"].length+"\"><span class='link' onclick='editFixedPackegeArchived("+objArray[i]['id']+");'>"+console_btn_edit+"</sapn> " +
						"</td>" +
						"</tr>";
					}else{
						text = "<tr id=\"row_"+objArray[i]['id']+"\" style=\"border: 0px;\"> " +
						"</tr>";
					}
					sumtext += text;
				}
			}else{
				text = "<tr>"+
				"<td colspan=\"13\" style=\"padding:0;\">"+
				"<table class=\"tablefoot\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
				"<tbody>"+
					"<tr>"+
						"<td width=\"33%\" align=\"left\">"+foor_page+"&nbsp;"+
							"<select name=\"selectpagearchived\" onchange=\"showArchivedFixedPackage()\">"+
							"</select>&nbsp;"+foor_of+"&nbsp;<span id=\"pageAmountarchived\">1</span>"+
						"</td>"+
						"<td width=\"31%\" align=\"center\">"+foor_view+
							"<select name=\"maxEntriesarchived\" onchange=\"showArchivedFixedPackage()\">"+
								"<option style=\"color:#000000\"  value=\"10\">10</option>"+
								"<option style=\"color:#000000\"  value=\"20\">20</option>"+
								"<option style=\"color:#000000\"  value=\"30\">30</option>"+
								"<option style=\"color:#000000\"  value=\"50\">50</option>"+
								"<option style=\"color:#000000\"  value=\"70\">70</option>"+
								"<option style=\"color:#000000\"  value=\"100\">100</option>"+
								"<option style=\"color:#000000\"  value=\"200\">200</option>"+
								"<option style=\"color:#000000\"  value=\"100000\">All</option>"+
							"</select>"+foor_rpp+" </td>" +
							"<td width=\"36%\" align=\"right\"><span id=\"previousarchived\">&lt;&lt;"+foor_pre+"</span> |" +
							" <span id=\"nextarchived\">"+foor_next+"&gt;&gt;</span></td></tr>"+
							"</tbody></table></td></tr>";
				sumtext += text;
			}
	}
	$("#showListArchived tr").not($("#showListArchived tr").first()).remove();
	$("#showListArchived").append(sumtext);
	$("#pageAmount").text(pageAmount);
	if(pagePointer+1 <= pageAmount){
		$("#nextarchived").attr("onclick","showArchivedFixedPackage(id)");
		$("#nextarchived").html("<a href=\"#\">Next&gt;&gt;</a>");
	}
	if(pagePointer > 1){
		$("#previousarchived").attr("onclick","showArchivedFixedPackage(id)");
		$("#previousarchived").html("<a href=\"#\">&lt;&lt;Previous</a>");
	}
	$("[name=maxEntriesarchived]").val(line);
	for ( var i = 0; i < pageAmount; i++) {
		$("[name=selectpagearchived]").append(
				$("<option>").val((i+1)).html((i+1)));
		}
	$("[name=selectpagearchived]").val(pagePointer);
}

function restorearchived(){
	var listCheckBox = "";
	var checkboxArchived = $('tr [name*=idarchived]');
	var line = $("[name=maxEntriesarchived]").val();
	var pagePointer = $("[name=selectpagearchived]").val();
	for(var i = 0;i<checkboxArchived.length;i++){
		if(checkboxArchived[i].checked == true){
			if($(checkboxArchived[i]).attr("value")!=null)
				listCheckBox += $(checkboxArchived[i]).attr("value")+",";
		}
	}
	var url = "/fixedpackageservice";
	var data = { func : "changeArchived",
			id : listCheckBox.substring(0,listCheckBox.length - 1),
			line: line,
			pagePointer: pagePointer,
			offset: (line*pagePointer)-line
		}
	simpleserviceWithArgs(url,data,showArchivedFixedPackageList);
}

function toggleSelectArchived(){
	if($("#showListArchived tr [type=checkbox]")[0].checked == true){
		for(var i = 0;i< $("#showListArchived tr [type=checkbox]").size();i++){
			$("#showListArchived tr [type=checkbox]")[i].checked = true;
		}
	}else{
		for(var i = 0;i< $("#showListArchived tr [type=checkbox]").size();i++){
			$("#showListArchived tr [type=checkbox]")[i].checked = false;
		}
	}
}

function cleartoggleSelectArchived(){
	if($("#showListArchived tr [type=checkbox]")[0].checked == true){
		for(var i = 0;i< $("#showListArchived tr [type=checkbox]").size();i++){
			$("#showListArchived tr [type=checkbox]")[i].checked = false;
		}
	}
}

function showdetailRoomType(dom,data){
	var dialog = editAdminDataDialog("top",dom,roomtype,"/adminconsole/PriceManager/Fixed/detailfixedpackage.jsp","addDialog",null,loadDetailRoomTypeElementFinishArchived,data);
}
function loadDetailRoomTypeElementFinishArchived(dialog,data){
	$('.ui-newdialog-button').hide();
	$('.ui-newdialog-content').css("width","250px");
	var text = "";
	for(var i =0;i<data.length;i++){
		text +='<tr><td><li>'+data[i].roomtype[0].shortName+'</li></td></tr>';
	}
	$("#detailRoomType").replaceWith(text);
}

function showdetailPrice(dom,data){
	var dialog = editAdminDataDialog("top",dom,datepernight,"/adminconsole/PriceManager/Fixed/detailfixedpackage.jsp","addDialog",null,loadDetailPriceElementFinishArchived,data);
}
function loadDetailPriceElementFinishArchived(dialog,data){
	$('.ui-newdialog-button').hide();
	$('.ui-newdialog-content').css("width","250px");
	var text = "";
	for(var i =0;i<data.length;i++){
		text +='<tr><td><li>'+data[i].roomtype[0].basePrice+' '+xSymbol+'</li></td></tr>';
	}
	$("#detailRoomType").replaceWith(text);
}